package foliotracker.GUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;


public abstract class DialogBase extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 1L;
	
	protected JButton okButton;
    protected JButton cancelButton;
    protected JPanel panel;
    
    public DialogBase(String title)
    {
    	super(title);
        super.setResizable(false);

        JPanel content = (JPanel)super.getContentPane();
        content.setBorder(new EmptyBorder(6, 6, 6, 6));
        content.setLayout(new BorderLayout());

        panel = new JPanel(new GridLayout(0, 2, 6, 6));
        content.add(panel, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 6, 6));

        okButton = new JButton("OK");
        okButton.addActionListener(this);
        buttonPanel.add(okButton);

        cancelButton = new JButton("Cancel");
        cancelButton.addActionListener(this);
        buttonPanel.add(cancelButton);

        content.add(buttonPanel, BorderLayout.PAGE_END);
    }
    
    protected void setPosition()
    {
    	Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        //super.pack();
        super.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
    }

    
    @Override
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == okButton) okButton_Clicked();
        else if (e.getSource() == cancelButton) cancelButton_Clicked();
        else return;
    }


	protected abstract void okButton_Clicked();
	protected abstract void cancelButton_Clicked();
}
